% Complete documentation on the extended LaTeX markup used for Python
% documentation is available in ``Documenting Python'', which is part
% of the standard documentation for Python.  It may be found online
% at:
%
%     http://www.python.org/doc/current/doc/doc.html

\documentclass{manual}

\title{mode.py}

\author{Chad W. L. Whitacre}

% Please at least include a long-lived email address;
% the rest is at your discretion.
\authoraddress{
	Zeta Design \&\ Development \\
	\url{http://www.zetadev.com/software/mode.py/} \\
	Email: \email{\ulink{chad@zetaweb.com}{mailto:chad@zetaweb.com}}
}

\date{November 7, 2006} % update before release!
%\date\today
				% Use an explicit date so that reformatting
				% doesn't cause a new date to be used.  Setting
				% the date to \today can be used during draft
				% stages to make it easier to handle versions.

\release{1.0a1}			% release version; this is used to define the
				% \version macro

\makeindex			% tell \index to actually write the .idx file
\makemodindex			% If this contains a lot of module sections.


\begin{document}

\maketitle

\begin{abstract}

\noindent
mode.py is a Python module that models the life-cycle of an application as a
series of four modes.

\end{abstract}

\chapter{Introduction}

It is often valuable to maintain a distinction between various phases of an
application's lifecycle. This module calls these phases \dfn{modes}, and
identifies four of them, given here in conceptual life-cycle order:

\begin{tableii}{l|l}{code}{Mode}{Description}
\lineii{debugging}{The application is being actively debugged; exceptions may
    trigger an interactive debugger.}
\lineii{development}{The application is being actively developed; however,
    exceptions should not trigger interactive debugging.}
\lineii{staging}{The application is deployed in a mock-production
    environment.}
\lineii{production}{The application is in live use by its end users.}
\end{tableii}


The expectation is that various aspects of the application---logging, exception
handling, data sourcing---will adapt to the current mode. The mode is set in the
\envvar{PYTHONMODE} environment variable. This module provides API for
interacting with this variable. If \envvar{PYTHONMODE} is unset, it will be set
to development when this module is imported.

\chapter{API}

\section{Functions}

\begin{funcdesc}{get}{}
Return the current \envvar{PYTHONMODE} setting as a lowercase string; will raise
\exception  {EnvironmentError} if the (case-insensitive) setting is not one of
\code{debugging}, \code{development}, \code{staging}, or \code{production}.
\end{funcdesc}

\begin{funcdesc}{set}{mode}
Given a mode, set the PYTHONMODE environment variable and refresh the module\'s
boolean members. If given a bad mode, \exception{ValueError} is raised.
\end{funcdesc}

\begin{funcdesc}{setAPI}{}
Refresh the module's boolean members. Call this if you ever change
\envvar{PYTHONPATH} directly in the \code{os.environ} mapping.
\end{funcdesc}

\section{Members}

The module defines a number of boolean attributes reflecting the current mode
setting, including abbreviations and combinations. Uppercase versions of each of
the following are also defined (e.g., \code{DEBUGGING}).

\begin{datadesc}{debugging, deb}
\class{True} if \envvar{PYTHONMODE} is set to \code{debugging}.
\end{datadesc}
\begin{datadesc}{development, dev}
\class{True} if \envvar{PYTHONMODE} is set to \code{development}.
\end{datadesc}
\begin{datadesc}{staging, st}
\class{True} if \envvar{PYTHONMODE} is set to \code{staging}.
\end{datadesc}
\begin{datadesc}{production, prod}
\class{True} if \envvar{PYTHONMODE} is set to \code{production}.
\end{datadesc}
\begin{datadesc}{debugging_or_development, debdev, devdeb}
\class{True} if \envvar{PYTHONMODE} is set to \code{debugging} or \code{development}.
\end{datadesc}
\begin{datadesc}{staging_or_production, stprod}
\class{True} if \envvar{PYTHONMODE} is set to \code{staging} or \code{production}.
\end{datadesc}


\chapter{Example}

Example usage:

\begin{verbatim}
>>> import mode
>>> mode.set('development')     # can set the mode at runtime
>>> mode.get()                  # and access the current mode
'development'
>>> mode.development            # module defines boolean constants
True
>>> mode.PRODUCTION             # uppercase versions are also defined
False
>>> mode.dev                    # as are abbreviations
True
>>> mode.DEBDEV, mode.stprod    # and combinations
(True, False)
\end{verbatim}

\chapter{Copyright and License}

Copyright (c) 2006, Chad Whitacre <chad@zetaweb.com>. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

\begin{itemize}

\item{Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.}

\item{Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.}

\item{Neither the name of Chad Whitacre nor the names of any other contributors
or copyright holders may be used to endorse or promote products derived from
this software without specific prior written permission.}

\end{itemize}

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.




\end{document}
